import { Effect, ImmerReducer, Subscription } from 'umi';
import { selFixedAssetListUrl } from '@/services/asset';
interface TableDataModel {
    key: string,
    name: string,
    age: number,
    address: string,

}

export interface TableModelState {
    name: string;
    data?: Array<TableDataModel>;
}

export interface TableModelType {
    namespace: 'table',
    state: TableModelState,
    effects: {
        queryTableData: Effect
    },
    reducers: {
        saveTableData: ImmerReducer<TableModelState>;
    },
    subcriptions?: { getTableData: Subscription }
}

const TableModel: TableModelType = {
    namespace: 'table',
    state: {
        name: '王文庭',
        data: [
            {
                key: '1',
                name: 'John Brown',
                age: 32,
                address: 'New York No. 1 Lake Park',
            },
            {
                key: '2',
                name: 'Jim Green',
                age: 42,
                address: 'London No. 1 Lake Park',
            },
            {
                key: '3',
                name: 'Joe Black',
                age: 32,
                address: 'Sidney No. 1 Lake Park',
            },
            {
                key: '4',
                name: 'Disabled User',
                age: 99,
                address: 'Sidney No. 1 Lake Park',
            },
        ],

    },
    effects: {
        *queryTableData({ payload }, { call, put }: { call: any; put: any }) {
            const res = yield call(selFixedAssetListUrl,payload);
            yield put({
                type: 'saveTableData',
                payload: res.data.rows,
            });

        }
    },
    reducers: {
        saveTableData(state, action) {
            state.data = action.payload;
        }
    }
}
export default TableModel;